package com.love.cloud.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.love.cloud.admin.api.entity.SysUserGroup;
import com.love.cloud.admin.api.entity.SysUserGroupMember;
import com.love.cloud.admin.api.vo.GroupMemberRoleVo;
import com.love.cloud.admin.api.vo.MobilizeVo;
import com.love.cloud.admin.api.vo.SysUserGroupPageVo;
import com.love.cloud.admin.service.SysUserGroupService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author hongdongqu
 */
@RestController
@RequestMapping("/user/group")
public class SysUserGroupController {
    @Resource
    private SysUserGroupService sysUserGroupService;

    @PostMapping("/add")
    public Object add(@RequestBody SysUserGroup sysUserGroup){
        return sysUserGroupService.add(sysUserGroup);
    }

    @PutMapping("/update")
    public Object update(@RequestBody SysUserGroup sysUserGroup){
        return sysUserGroupService.update(sysUserGroup);
    }

    @DeleteMapping("/delete/{id}")
    public Object delete(@PathVariable Long id){
        return sysUserGroupService.delete(id);
    }


    @GetMapping("/getOne/{id}")
    public Object getOne(@PathVariable Long id){
        return sysUserGroupService.getById(id);
    }

    @GetMapping("/groupMemberPage")
    public Object page(Page page,@Valid SysUserGroupPageVo sysUserGroupPageVo){
        return sysUserGroupService.groupMemberPage(page,sysUserGroupPageVo);
    }

    @GetMapping("/list")
    public Object list(){
        return sysUserGroupService.getList();
    }

    @ApiOperation(value = "人员调动")
    @PostMapping(value = "/mobilize")
    public Object mobilize(@Valid @RequestBody MobilizeVo mobilizeVo) throws Exception {
        sysUserGroupService.mobilize(mobilizeVo);
        return "调动成功";
    }

    @ApiOperation(value = "移除组成员")
    @PostMapping(value = "/removeGroupMember")
    public Object removeGroupMember(@RequestBody SysUserGroupMember sysUserGroupMember) throws Exception {
        sysUserGroupService.removeGroupMember(sysUserGroupMember);
        return "移除成功";
    }

    @ApiOperation(value = "获取到用户组成员")
    @GetMapping(value = "/getAllGroupMember")
    public Object getAllGroupMember(SysUserGroupMember sysUserGroupMember) throws Exception {
        return sysUserGroupService.getAllGroupMember(sysUserGroupMember);
    }


    @ApiOperation(value = "设置组成员角色")
    @PostMapping(value = "/setGroupMemberRole")
    public Object setGroupMemberRole(@Valid @RequestBody GroupMemberRoleVo groupMemberRoleVo) throws Exception {
        sysUserGroupService.setGroupMemberRole(groupMemberRoleVo);
        return "设置成功";
    }

}
